package com.mysterymall.Controller;

import cn.dev33.satoken.stp.StpUtil;
import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Model.Dto.LoginDto;
import com.mysterymall.Model.Dto.UserDto;
import com.mysterymall.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.IOException;

/**
 * @ClassName com.mysterymall.Controller
 * @Description
 * @Author HuangWX
 * @Time 2023/10/30  23:14
 */

@RestController
@RequestMapping("/user")
public class UserCont {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param loginDto 登录信息
     * @return Result
     */
    @PostMapping("/login")
    @Log
    public Result login(@Valid @RequestBody LoginDto loginDto){
         return userService.login(loginDto);
    }


    /**
     * 获取用户信息
     * @return Result
     */
    @GetMapping("/userInfo")
    @Log
    public Result userinfo(){
        return userService.userInfo();
    }


    /**
     * 注册
     * @param loginDto 注册信息
     * @return Result
     */
    @PostMapping("/registration")
    @Log
    public Result registration(@RequestBody LoginDto loginDto, HttpServletRequest request) throws IOException {
        return userService.registration(loginDto,request);
    }

    /**
     * 获取用户余额和佣金
     * @return Result
     */
    @GetMapping("/getBalance")
    @Log
    public Result getBalance(){
        return userService.getBalance();
    }

    /**
     * 修改用户信息
     * @param userDto 用户信息
     * @return Result
     */
    @PostMapping("/changeInfo")
    @Log
    public Result changeInfo(@RequestBody UserDto userDto){
         return  userService.changeInfo(userDto);
    }

    /**
     * 修改用户信息
     * @return Result
     */
    @PostMapping("/updateInfo")
    public Result updateInfo(){
        return null;
    }


    /**
     * 退出登录
     * @return Result
     */
    @GetMapping("/logout")
    public Result logout(){
        StpUtil.logout();
        return  new Result(200,"message.userCont.loginOut.success");
    }


    @GetMapping("/getMyAddress")
    @Log
    public Result getMyAddress(){
        return userService.getMyAddress();
    }


    @GetMapping("/getAdminList")
    @Log
    public Result getAdminList(){
        return userService.getAdminList();
    }


    @PostMapping("/addUser")
    @Log
    public Result addUser(@RequestBody UserDto userDto){
        return userService.addUser(userDto);
    }



    @GetMapping("/getAdminLog")
    @Log
    public Result getAdminLog(@RequestParam("page") Integer page,@RequestParam("size") Integer size,@RequestParam("userId")String userId){
        return userService.getAdminLog(page,size,userId);
    }
}
